<?php

jimport('joomla.application.component.controller');

class bgController extends JController {
    public function __construct(){
        parent::__construct();
          
        $this->model = $this->getModel();
        $this->aut = new bgAuthorize();
    }
    
    public function display($cachable = false, $urlparams = false) {
        parent::display($cachable, $urlparams);
    }
    
    public function savetemp(){ 
        
        // get data form
        $data = &JRequest::getVar('jform');
        $action = &JRequest::getVar('action');   
        // check addnew or edit
        if($action == "edit"){
            $addNew = false;
        }else{
            $addNew = true;
        }
        
        //SET DATA
        $data['OCBA_USER_CREATE'] = $this->aut->getUserID();
        $data['OCBA_WEBF'] = 0;
        $data['OCBA_FLAG'] = 1;
        $data['OCBA_DBSY'] = 0; //flag dong bo. 0: chua dong bo, 1: da dong bo
        //SET DATA UPDATE
        $data['OCBA_DATE'] = date('Y-m-d H:i:s');
        
        if(isset($_POST['cb1'])){
            $data['OCBA_PUTF'] = 1;
        }
        if(isset($_POST['cb2'])){
            $data['OCBA_LARF'] = 1;
        }
        if(isset($_POST['cb3'])){
            $data['OCBA_CANF'] = 1;
        }
        if(isset($_POST['cb4'])){
            $data['OCBA_YACF'] = 1;
        }
        if(isset($_POST['cb5'])){
            $data['OCBA_SCHF'] = 1;
        }
        if(isset($_POST['cb6'])){
            $data['OCBA_OUTF'] = 1;
        }
        $data['OCBA_IMG'] = $_POST['jformOCBA_IMG'];
        if(empty($data['OCBA_TERM_CODE'])){
            $data['OCBA_TERM_CODE'] = null;
        }
        if(empty($data['OCBA_TOWN_CODE'])){
            $data['OCBA_TOWN_CODE'] = null;
        }
        if(empty($data['OCBA_PETT_CODE'])){
            $data['OCBA_PETT_CODE'] = null;
        }
        if(empty($data['OCBA_CLUB_CODE'])){
            $data['OCBA_CLUB_CODE'] = null;
        }
        if(empty($data['OCBA_CLUB_DEPEND'])){
            $data['OCBA_CLUB_DEPEND'] = null;
        }
        
        if(empty($data['OCBA_loaihinh_CODE'])){
            $data['OCBA_LOAIHINH'] = null;
        }else{
            $data['OCBA_LOAIHINH'] = $data['OCBA_loaihinh_CODE'];
        }
        
        /**
         * check data
        **/
        if(empty($data['OCBA_CODE'])){
            //$error = "VUI LONG NHAP MA TRUNG TAM - CAU LAC BO";
            $error = "センター・クラブコードを入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }else{
            
            /* check OCBA_CODE exist */
            if($addNew){
                /* check OCBA_CODE invalid */
                $char = substr($data['OCBA_CODE'],0,1);
                if($data['rd_centerclub']  == '1'){
                    //check first char
                    if($char != '0'){
                        //$error = "Ma trung tam phai bat dau bang so 0";
                        $error = "センターコードは「0」で始まる4桁の数値で入力してください。";
                        JRequest::setVar('task','error');
                        JFactory::getApplication()->enqueueMessage($error, 'error');
                        
                        parent::display();
                        return;
                    }
                    //check length
                    if(strlen($data['OCBA_CODE']) != 4){
                        //$error = "Ma trung tam phai bat dau bang so 0";
                        $error = "センターコードは「0」で始まる4桁の数値で入力してください。";
                        JRequest::setVar('task','error');
                        JFactory::getApplication()->enqueueMessage($error, 'error');
                        
                        parent::display();
                        return;
                    }
                    
                    //check exist
                    if($this->model->checkExistOCBA_CODE($data['OCBA_CODE'])){
                        //$error = "MA TRUNG TAM NAY DA CO ROI";
                        $error = "指定したセンターコードはすでに存在しています。";
                        JRequest::setVar('task','error');
                        JFactory::getApplication()->enqueueMessage($error, 'error');
                        
                        parent::display();
                        return;
                    }
                }else{
                    if($char != '1'){
                        //$error = "Ma cau lac bo phai bat dau bang so 1";
                        $error = "クラブコードは「1」で始まる4桁の数値で入力してください。";
                        JRequest::setVar('task','error');
                        JFactory::getApplication()->enqueueMessage($error, 'error');
                        
                        parent::display();
                        return;
                    }
                    
                    if(strlen($data['OCBA_CODE']) != 4){
                        //$error = "Ma cau lac bo phai bat dau bang so 1";
                        $error = "クラブコードは「1」で始まる4桁の数値で入力してください。";
                        JRequest::setVar('task','error');
                        JFactory::getApplication()->enqueueMessage($error, 'error');
                        
                        parent::display();
                        return;
                    }
                    
                    //check exist
                    if($this->model->checkExistOCBA_CODE($data['OCBA_CODE'])){
                        //$error = "MA CLB NAY DA CO ROI";
                        $error = "指定したクラブコードはすでに存在しています。";
                        JRequest::setVar('task','error');
                        JFactory::getApplication()->enqueueMessage($error, 'error');
                        
                        parent::display();
                        return;
                    }
                }
                
                
            }
            
            if($this->model->savetemp($data, $addNew)){
                
                
                $this->setRedirect('index.php?option=com_center');
            }else{
                //JError::raiseError(500, 'Error ! Can\'t save' );
                //$error = "Error! Can't save!";
                $error = "エラー！データが記録されません。";
                JRequest::setVar('task','');
                JFactory::getApplication()->enqueueMessage($error, 'error');
            }
        }
        
        parent::display();
    }
    
    
    public function save(){
        $data = &JRequest::getVar('jform');
        
        // check addnew or edit
        if($this->getModel()->checkExistID($data['OCBA_CODE'])){
            $addNew = false;
        }else{
            $addNew = true;
        }
        $data['OCBA_USER_CREATE'] = $this->aut->getUserID();
        $data['OCBA_WEBF'] = 1;
        $data['OCBA_FLAG'] = 1;
        $data['OCBA_DBSY'] = 0; //flag dong bo. 0: chua dong bo, 1: da dong bo
        //set data update
        $data['OCBA_DATE'] = date('Y-m-d H:i:s');
        
        if(isset($_POST['cb1'])){
            $data['OCBA_PUTF'] = 1;
        }
        if(isset($_POST['cb2'])){
            $data['OCBA_LARF'] = 1;
        }
        if(isset($_POST['cb3'])){
            $data['OCBA_CANF'] = 1;
        }
        if(isset($_POST['cb4'])){
            $data['OCBA_YACF'] = 1;
        }
        if(isset($_POST['cb5'])){
            $data['OCBA_SCHF'] = 1;
        }
        if(isset($_POST['cb6'])){
            $data['OCBA_OUTF'] = 1;
        }
        
        $data['OCBA_IMG'] = $_POST['jformOCBA_IMG'];
        if(empty($data['OCBA_TERM_CODE'])){
            $data['OCBA_TERM_CODE'] = null;
        }
        if(empty($data['OCBA_TOWN_CODE'])){
            $data['OCBA_TOWN_CODE'] = null;
        }
        if(empty($data['OCBA_PETT_CODE'])){
            $data['OCBA_PETT_CODE'] = null;
        }
        if(empty($data['OCBA_CLUB_CODE'])){
            $data['OCBA_CLUB_CODE'] = null;
        }
        if(empty($data['OCBA_CLUB_DEPEND'])){
            $data['OCBA_CLUB_DEPEND'] = null;
        }
        
        if(empty($data['OCBA_loaihinh_CODE'])){
            $data['OCBA_LOAIHINH'] = null;
        }else{
            $data['OCBA_LOAIHINH'] = $data['OCBA_loaihinh_CODE'];
        }
        /**
         * check data
        **/
        if(empty($data['OCBA_CODE'])){
            //$error = "VUI LONG NHAP MA TRUNG TAM - CAU LAC BO";
            $error = "センター・クラブコードを入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            
            parent::display();
            return;
        }
        if(($data['rd_centerclub'] == '1') && (substr($data['OCBA_CODE'],0,1) != '0')){
            //$error = "Ma trung tam phai bat dau bang so 0";
            $error = "センターコードは「0」で始まる4桁の数値で入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            
            parent::display();
            return;
        }
        if(($data['rd_centerclub'] == '1') && (strlen($data['OCBA_CODE']) != 4)){
            //$error = "Ma trung tam phai bat dau bang so 0";
            $error = "センターコードは「0」で始まる4桁の数値で入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            
            parent::display();
            return;
        }
        if(($data['rd_centerclub'] == '0') && (substr($data['OCBA_CODE'],0,1) != '1')){
            //$error = "Ma cau lac bo phai bat dau bang so 1";
            $error = "クラブコードは「1」で始まる4桁の数値で入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            
            parent::display();
            return;
        }
        if(($data['rd_centerclub'] == '0') && (strlen($data['OCBA_CODE']) != 4)){
            //$error = "Ma cau lac bo phai bat dau bang so 1";
            $error = "クラブコードは「1」で始まる4桁の数値で入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            
            parent::display();
            return;
        }
        if($data['rd_centerclub'] == '1'){
            if($this->model->checkExistOCBA_CODE($data['OCBA_CODE'])){
                //$error = "MA TRUNG TAM NAY DA CO ROI";
                $error = "指定したセンターコードはすでに存在しています。";
                JRequest::setVar('task','error');
                JFactory::getApplication()->enqueueMessage($error, 'error');
                
                parent::display();
                return;
            }
        }
        if($data['rd_centerclub'] == '0'){
            if($this->model->checkExistOCBA_CODE($data['OCBA_CODE'])){
                //$error = "MA CLB NAY DA CO ROI";
                $error = "指定したクラブコードはすでに存在しています。";
                JRequest::setVar('task','error');
                JFactory::getApplication()->enqueueMessage($error, 'error');
                
                parent::display();
                return;
            }
        
        }
        if(empty($data['OCBA_NAME'])){
            //$error = "VUI LONG NHAP TEN TRUNG TAM - CAU LAC BO";
            $error = "センター・クラブ名を入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            
            parent::display();
            return;
        }
        if(empty($data['OCBA_SHOR'])){
            //$error = "VUI LONG NHAP TEN VIET TAT CUA TRUNG TAM - CAU LAC BO";
            $error = "センター・クラブ略名を入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            
            parent::display();
            return;
        }
        if(empty($data['OCBA_KANA'])){
            //$error = "VUI LONG NHAP TEN KANA CUA TRUNG TAM - CAU LAC BO";
            $error = "センター・クラブのカナ名を入力してください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            
            parent::display();
            return;
        }
        if(empty($data['OCBA_TOWN_CODE'])){
            //$error = "VUI LONG NHAP MA THANH PHO";
            $error = "市町村コードを入力しください。";
            JRequest::setVar('task','error');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            
            parent::display();
            return;
        
        }
            
        /* check center depend when add club */
        if($addNew){
            if($data['rd_centerclub'] == '0'){
                if($data['OCBA_CLUB_DEPEND']  == null){
                    //$error = "vui long chon trung tam truc thuoc";
                    $error = "所属するセンターを選択してください。";
                    JRequest::setVar('task','error');
                    JFactory::getApplication()->enqueueMessage($error, 'error');
                    
                    parent::display();
                    return;
                }
                
                if($data['OCBA_CLUB_CODE'] == null){
                    //$error = "Vui long chon loai cau lac bo";
                    $error = "クラブ種別を選択してください。";
                    JRequest::setVar('task','error');
                    JFactory::getApplication()->enqueueMessage($error, 'error');
                    
                    parent::display();
                    return;
                }
                
            }
        }else{
            if($data['check_cc']  == '0' ){
                if($data['OCBA_CLUB_DEPEND']  == null){
                    //$error = "VUI LONG CHON TRUNG TAM TRUC THUOC";
                    $error = "所属するセンターを選択してください。";
                    JRequest::setVar('task','error');
                    JFactory::getApplication()->enqueueMessage($error, 'error');
                    
                    parent::display();
                    return;
                }
                
                if($data['OCBA_CLUB_CODE'] == null){
                    //$error = "Vui long chon loai cau lac bo";
                    $error = "クラブ種別を選択してください。";
                    JRequest::setVar('task','error');
                    JFactory::getApplication()->enqueueMessage($error, 'error');
                    
                    parent::display();
                    return;
                }
            }
        }
        /* save data */
        
        if($this->model->savetemp($data, $addNew)){
            
            $this->setRedirect('index.php?option=com_center');
           
        }else{
            //JError::raiseError(500, 'Error ! Can\'t save center,club' );
            //$error = "Error! Can't save!";
            $error = "エラー！データが記録されません。";
            JRequest::setVar('task','');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }
        
        
        parent::display();
    }
    
    /**
     *  remove ocba
    **/
    public function remove(){
    	$cid = JRequest::getVar('cid');
                
        foreach($cid as $value){
            //get image name
            $img_name = $this->getModel()->getImgNameFromID($value);
            //Del Image
            if($img_name != null){
                $path = "uploads/images/com_center/$img_name";
                if(file_exists($path)){
                    $del = unlink($path);
                }
            }
        }
           
        if($this->model->remove($cid)){
            $this->setRedirect('index.php?option=com_center');
        }else{
            //$err = "Error ! Cant\'t delete";
            //$error = "Error! Can't save!";
            $error = "エラー！データが記録されません。";
            JRequest::setVar('task','');
            JFactory::getApplication()->enqueueMessage($error, 'error');
            $this->setRedirect('index.php?option=com_center');
            //JError::raiseError(500, 'Error ! Can\'t delete' );
        }
    }
    
    /**
	*export data from mysql (table OCBA) to file csv
	*/
    public function export_csv_ocba(){
        if(HelperBG::export_csv_ocba()){
            $this->setRedirect('index.php?option=com_center');
        }
        else{
            //JError::raiseError(500, 'Error ! Can\t export file CSV');
            $error = "エラー！CSVファイルが出力されません。";
            JRequest::setVar('task','');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }
        parent::display();
    }
    
    /**
	*Dong bo data from mysql (table OCBA) to file csv
	*/
    public function dongbo_csv_ocba(){
        if(HelperBG::dongbo_csv_ocba()){
            $this->setRedirect('index.php?option=com_center');
        }
        else{
            //JError::raiseError(500, 'Error ! Can\t export file CSV');
            $error = "エラー！CSVファイルが出力されません。";
            JRequest::setVar('task','');
            JFactory::getApplication()->enqueueMessage($error, 'error');
        }
        parent::display();
    }
    
    /**
     * search list town
    **/
    public function searchTown(){
        $search['TOWN_NAME'] =  JRequest::getVar('TOWN_NAME');
        $this->search_name = $search['TOWN_NAME'];
        $result = $this->getModel()->getAllListTown($search);
        
        echo '<div class="the_scroll">
               <table class="adminlist">
        		<thead>
        			<tr>
        				<th class="th20">
        					市町村コード	
                        </th>
                        <th class="th40">
                            市町村名
                        </th>
        				<th class="th40">
                            市町村名カナ				
                        </th>
        				
        			</tr>
        		</thead>
            		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_town_code" onclick="document.id('."'town_code_temp'".').value='."'".$row->TOWN_CODE."'".';" >'. $row->TOWN_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_town_code" onclick="document.id('."'town_code_temp'".').value='."'".$row->TOWN_CODE."'".';" >'. $row->TOWN_NAME.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_town_code" onclick="document.id('."'town_code_temp'".').value='."'".$row->TOWN_CODE."'".';" >'. $row->TOWN_KANA.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="3">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="town_code_temp" id="town_code_temp" value="" />
                </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    //Clear Search Town
    public function clearSearchTown(){
        $result = $this->getModel()->getAllListTown();
        
        echo '<div class="the_scroll">
               <table class="adminlist">
        		<thead>
        			<tr>
        				<th class="th20">
        					市町村コード	
                        </th>
                        <th class="th40">
                            市町村名
                        </th>
        				<th class="th40">
                            市町村名カナ				
                        </th>
        				
        			</tr>
        		</thead>
            		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_town_code" onclick="document.id('."'town_code_temp'".').value='."'".$row->TOWN_CODE."'".';" >'. $row->TOWN_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_town_code" onclick="document.id('."'town_code_temp'".').value='."'".$row->TOWN_CODE."'".';" >'. $row->TOWN_NAME.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_town_code" onclick="document.id('."'town_code_temp'".').value='."'".$row->TOWN_CODE."'".';" >'. $row->TOWN_KANA.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="3">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="town_code_temp" id="town_code_temp" value="" />
                </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    //search Term
    public function searchTerm(){
        $search['TERM_NAME'] =  JRequest::getVar('TERM_NAME');
        $this->search_name = $search['TERM_NAME'];
        $result = $this->getModel()->getAllTerm($search);
        
        echo '<div class="the_scroll">
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th20">
                					期別コード		
                                </th>
                                <th class="th40">
                                    期
                                </th>
                				<th class="th40">
                                    年度				
                                </th>
                				
                			</tr>
                		</thead>        		
                		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_term_code" onclick="document.id('."'term_code_temp'".').value='."'".$row->TERM_CODE."'".';" >'.$row->TERM_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_term_code" onclick="document.id('."'term_code_temp'".').value='."'".$row->TERM_CODE."'".';" >'.$row->TERM_NAME.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_term_code" onclick="document.id('."'term_code_temp'".').value='."'".$row->TERM_CODE."'".';" >'.$row->TERM_YEAR.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="3">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="term_code_temp" id="term_code_temp" value="" />
                </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    //Clear Search Town
    public function clearSearchTerm(){
        $result = $this->getModel()->getAllTerm();
        
        echo '<div class="the_scroll">
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th20">
                					期別コード		
                                </th>
                                <th class="th40">
                                    期
                                </th>
                				<th class="th40">
                                    年度				
                                </th>
                				
                			</tr>
                		</thead>        		
                		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_term_code" onclick="document.id('."'term_code_temp'".').value='."'".$row->TERM_CODE."'".';" >'.$row->TERM_CODE.'</a>
                            </td>
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_term_code" onclick="document.id('."'term_code_temp'".').value='."'".$row->TERM_CODE."'".';" >'.$row->TERM_NAME.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_term_code" onclick="document.id('."'term_code_temp'".').value='."'".$row->TERM_CODE."'".';" >'.$row->TERM_YEAR.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="3">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="term_code_temp" id="term_code_temp" value="" />
                </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    //search Pett
    public function searchPett(){
        $search['PEDE_NAME'] =  JRequest::getVar('PEDE_NAME');
        $this->search_name = $search['PEDE_NAME'];
        $result = $this->getModel()->getAllListPett($search);
        
        echo '<div class="the_scroll">
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th20">
                					類型詳細コード	
                                </th>
                                <th class="th40">
                                    類型
                                </th>
                				<th class="th40">
                                    類型メモ				
                                </th>
                				
                			</tr>
                		</thead>        		
                		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_pett_code" onclick="document.id('."'pett_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PETT_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_pett_code" onclick="document.id('."'pett_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PEDE_NAME.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_pett_code" onclick="document.id('."'pett_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PETT_NOTE.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="3">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="pett_code_temp" id="pett_code_temp" value="" />
                </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    //Clear Search Pett
    public function clearSearchPett(){
        $result = $this->getModel()->getAllListPett();
        
        echo '<div class="the_scroll">
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th20">
                					類型詳細コード	
                                </th>
                                <th class="th40">
                                    類型
                                </th>
                				<th class="th40">
                                    類型メモ				
                                </th>
                				
                			</tr>
                		</thead>       		
                		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_pett_code" onclick="document.id('."'pett_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PETT_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_pett_code" onclick="document.id('."'pett_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PEDE_NAME.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_pett_code" onclick="document.id('."'pett_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PETT_NOTE.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="3">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="pett_code_temp" id="pett_code_temp" value="" />
                </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    
    
    
    
    //
    //search loai hinh
    public function searchLoaihinh(){
        $search['PEDE_NAME'] =  JRequest::getVar('PEDE_NAME');
        $this->search_name = $search['PEDE_NAME'];
        $result = $this->getModel()->getAllListPett($search);
        
        echo '<div class="the_scroll">
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th20">
                					類型詳細コード	
                                </th>
                                <th class="th40">
                                    類型
                                </th>
                				<th class="th40">
                                    類型メモ				
                                </th>
                				
                			</tr>
                		</thead>        		
                		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_loaihinh_code" onclick="document.id('."'loaihinh_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PETT_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_loaihinh_code" onclick="document.id('."'loaihinh_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PEDE_NAME.'</a>
                            </td>
                            <td class="left">
                                <a href="javascript:void(0,0);" class="link_loaihinh_code" onclick="document.id('."'loaihinh_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PETT_NOTE.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="3">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="loaihinh_code_temp" id="loaihinh_code_temp" value="" />
                </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    //Clear Search Loaihinh
    public function clearSearchLoaihinh(){
        $result = $this->getModel()->getAllListPett();
        
        echo '<div class="the_scroll">
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th20">
                					類型詳細コード	
                                </th>
                                <th class="th40">
                                    類型
                                </th>
                				<th class="th40">
                                    類型メモ				
                                </th>
                				
                			</tr>
                		</thead>       		
                		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_loaihinh_code" onclick="document.id('."'loaihinh_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PETT_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_loaihinh_code" onclick="document.id('."'loaihinh_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PEDE_NAME.'</a>
                            </td>
                            <td class="left">
                                <a href="javascript:void(0,0);" class="link_loaihinh_code" onclick="document.id('."'loaihinh_code_temp'".').value='."'".$row->PETT_CODE."'".';" >'.$row->PETT_NOTE.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="3">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="loaihinh_code_temp" id="loaihinh_code_temp" value="" />
                </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    
    //
    
    //search Club
    public function searchClub(){
        $search['CLUB_NAME'] =  JRequest::getVar('CLUB_NAME');
        $this->search_name = $search['CLUB_NAME'];
        $result = $this->getModel()->getAllListClub($search);
        
        echo '
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th30">
                					クラブ種別コード	
                                </th>
                                <th class="th70">
                                    クラブ種別名
                                </th>
                			</tr>
                		</thead>       		
                		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_club_code" onclick="document.id('."'club_code_temp'".').value='."'".$row->CLUB_CODE."'".';" >'.$row->CLUB_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_club_code" onclick="document.id('."'club_code_temp'".').value='."'".$row->CLUB_CODE."'".';" >'.$row->CLUB_NAME.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="2">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="club_code_temp" id="club_code_temp" value="" />';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    //Clear Search Club
    public function clearSearchClub(){
        $result = $this->getModel()->getAllListClub();
        
        echo '
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th30">
                					クラブ種別コード	
                                </th>
                                <th class="th70">
                                    クラブ種別名
                                </th>
                			</tr>
                		</thead>       		
                		<tbody>';
                      
                        if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0,0);" class="link_ocba_code" onclick="document.id('."'club_code_temp'".').value='."'".$row->CLUB_CODE."'".';" >'.$row->CLUB_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0,0);" class="link_ocba_code" onclick="document.id('."'club_code_temp'".').value='."'".$row->CLUB_CODE."'".';" >'.$row->CLUB_NAME.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="2">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="club_code_temp" id="club_code_temp" value="" />';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    
    /* search center pop up */
    public function searchCenter(){
        $search['search_name'] =  JRequest::getVar('search_name');
        
        $this->search_name = $search['search_name'];
        $result = $this->getModel()->getAllListCenter($search);
        
        echo '
                <div class="the_scroll">
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th30">
                					番号	
                                </th>
                                <th class="th70">
                                    名称
                                </th>
                			</tr>
        		          </thead>     		
                		<tbody>';
                      
                          if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0);" class="link_ocba_depend" id="jformOCBA_CODE" onclick="document.id('."'".'center_code_temp'."'".').value='."'".$row->OCBA_CODE."'".';" >'.$row->OCBA_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0);" class="link_ocba_depend" id="jformOCBA_CODE" onclick="document.id('."'".'center_code_temp'."'".').value='."'".$row->OCBA_CODE."'".';" >'.$row->OCBA_NAME.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="2">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="center_code_temp" id="center_code_temp" value="" />
                 </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    
    /* clear center pop up */
    public function clearSearchCenter(){
        
        $result = $this->getModel()->getAllListCenter();
        
        echo '
                <div class="the_scroll">
                   <table class="adminlist">
                		<thead>
                			<tr>
                				<th class="th30">
                					番号	
                                </th>
                                <th class="th70">
                                    名称
                                </th>
                			</tr>
        		          </thead>     		
                		<tbody>';
                      
                          if($result != null){
                            foreach($result as $k=>$row){
                 echo '            
                		  <tr class="row'.($k%2).'">
                			<td class="center">
                                <a href="javascript:void(0);" class="link_ocba_depend" id="jformOCBA_CODE" onclick="document.id('."'".'center_code_temp'."'".').value='."'".$row->OCBA_CODE."'".';" >'.$row->OCBA_CODE.'</a>
                            </td>
                            <td class="center">
                                <a href="javascript:void(0);" class="link_ocba_depend" id="jformOCBA_CODE" onclick="document.id('."'".'center_code_temp'."'".').value='."'".$row->OCBA_CODE."'".';" >'.$row->OCBA_NAME.'</a>
                            </td>
                		  </tr>';
                        
                            }
                        }else{
                echo '      <tr>
                                <td class="center" colspan="2">データは見つかりませんでした。</td>
                            </tr>';
                      
                        }
                     
            	echo '</tbody>
                   
                	</table>
                    <input type="hidden" name="center_code_temp" id="center_code_temp" value="" />
                 </div>';
        
        $app = &JFactory::getApplication();
        $app->close();
    }
    

}